package jwj8508.swing;

import java.awt.Color;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;

public class SwingToolBar extends JToolBar {
	private static SwingMenuActionListener action = null;
	private String imgPath = "/images/toolbar/";
	private String imgExt = ".png";
	
	public SwingToolBar() {
		setFloatable(false);
		setBorder(new EmptyBorder(0,0,0,0));
		action = new SwingMenuActionListener();
		addToolBarButton();	// 툴바에 버튼 추가
	}

	private void addToolBarButton() {
		add(makeToolBarButton("new", "새로 만들기"));
		add(makeToolBarButton("open", "열기"));
		add(makeToolBarButton("close", "닫기"));
		add(makeToolBarButton("save", "저장하기"));
		add(makeToolBarButton("user", "회원"));
		add(makeToolBarButton("calendar", "일정"));
		add(makeToolBarButton("lock", "잠금"));
	}
	
	private JButton makeToolBarButton(String img, String tooltip) {
		JButton btn = new JButton();
		btn.setBorder(new EmptyBorder(5, 10, 5, 10));
		//btn.setBackground(new Color(220, 220, 220));
		
		btn.setFocusable(false);
		btn.addActionListener(action);
		btn.setActionCommand(img);
		btn.setToolTipText(tooltip);
		
		URL iconPath = getClass().getResource(imgPath + img + imgExt);
		btn.setIcon(new ImageIcon(iconPath));
		
		return btn;
	}
	
}
